<?php $this->_extends('../_layouts/default_layout');?>
<?php $this->_block('contents');?>
<script type="text/javascript">
$(function(){
	$(".datepicker").datepicker({dateFormat: 'yy-mm-dd', changeMonth: true});
});
</script>
<fieldset><legend>查询条件</legend>
<form method="get">
<?include (Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
<table class="form_table">
<tr>
	<th>出库时间</th>
	<td>
		<input type="text" name="begin_shipped_time" class="datepicker" value="<?=isset($_GET['begin_shipped_time']) ? $_GET['begin_shipped_time'] : date('Y-m-01', CURRENT_TIMESTAMP)?>" /> to
		<input type="text" name="end_shipped_time" class="datepicker" value="<?=isset($_GET['end_shipped_time']) ? $_GET['end_shipped_time'] : date('Y-m-d', CURRENT_TIMESTAMP)?>" />
	</td>
</tr>
<tr>
	<th>产品编号</th>
	<td><input type="text" name="product_number" value="<?=isset($_GET['product_number']) ? $_GET['product_number'] : ''?>" /></td>
</tr>
<tr>
	<th>仓库</th>
	<td>
		<select name="warehouse_id">
			<option value="">请选择</option>
			<?foreach ($warehouse as $w):?>
			<option value="<?=$w['id']?>" <?=isset($_GET['warehouse_id']) && $_GET['warehouse_id'] == $w['id'] ? 'selected="selected"' : ''?>><?=$w['name']?></option>
			<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<td colspan="2">
		<input type="hidden" name="is_search" value="1" />
		<input type="submit" class="button" value="查询" />
	</td>
</tr>
</table>
</form>
</fieldset>
<?if (isset($_GET['is_search']) && ! empty($_GET['product_number'])):?>
<table class="list_table" width="60%">
<tr>
	<th>仓库</th>
	<th>店铺</th>
	<th width="50">数量</th>
	<th>数量占比</th>
	<th>销售金额</th>
	<th>销售金额占比</th>
	<th>产品金额</th>
	<th>产品金额占比</th>
</tr>
<?foreach ($product_sales['report'] as $r):?>
<tr>
	<td><?=$r['warehouse_name'];?></td>
	<td></td>
	<td></td>
	<td></td>
	<td></td>
	<td></td>
	<td></td>
	<td></td>
</tr>
<?foreach ($r['shop_report'] as $rs):?>
<tr>
	<td></td>
	<td><?=$rs['name'];?></td>
	<td><?=$rs['sales_quantity'];?></td>
	<td><?=empty($product_sales['total_sales_quantity']) ? '0.00%' : sprintf('%.2f', $rs['sales_quantity'] / $product_sales['total_sales_quantity'] * 100) . '%';?></td>
	<td><?=sprintf('%.2f', $rs['sales_amount']);?></td>
	<td><?=empty($product_sales['total_sales_amount']) ? '0.00%' : sprintf('%.2f', $rs['sales_amount'] / $product_sales['total_sales_amount'] * 100) . '%';?></td>
	<td><?=sprintf('%.2f', $rs['product_amount']);?></td>
	<td><?=empty($product_sales['total_product_amount']) ? '0.00%' : sprintf('%.2f', $rs['product_amount'] / $product_sales['total_product_amount'] * 100) . '%';?></td>
</tr>
<?endforeach;?>
<?if (count($r['shop_report']) === 0):?>
<tr>
	<td></td>
	<td>-</td>
	<td>0</td>
	<td>0.00%</td>
	<td>0.00</td>
	<td>0.00%</td>
	<td>0.00</td>
	<td>0.00%</td>
</tr>
<?endif;?>
<?endforeach;?>
<tr>
	<td colspan="2" align="right"><strong>合计：</strong></td>
	<td><?=$product_sales['total_sales_quantity'];?></td>
	<td></td>
	<td><?=sprintf('%.2f', $product_sales['total_sales_amount']);?></td>
	<td></td>
	<td><?=sprintf('%.2f', $product_sales['total_product_amount']);?></td>
	<td></td>
</tr>
</table>
<?endif;?>
<?php $this->_endblock();?>